let processData = (item) => {
  let data = {
    name: item.name,
    initiatorType: item.initiatorType,
    duration: item.duration,
  };
  return data;
};
export default {
  init(cb) {
    //获取资源相关信息
    if (window.PerformanceObserver) {
      let observer = new PerformanceObserver((list) => {
        let data = list.getEntries();
        cb(processData(data[0]));
      });
      observer.observe({ entryTypes: ["resource"] });
    } else {
      window.onload = function () {
        const data = performance
          .getEntriesByType("resource")
          .map((item) => processData(item));
        cb(data);
      };
    }
  },
};
